package com.xiaoxi.userserver.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxi.userserver.mapper.user.BMSUserPasswordChangeLogMapper;
import com.xiaoxi.userserver.service.user.BMSUserPasswordChangeLogService;
import com.xiaoxi.domain.user.BMSUserPasswordChangeLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @Author xiaoxi
 * @ProjectName springcloudbms
 * @PackageName com.userserver.service.impl
 * @ClassName BMSUserPasswordChangeLogServiceImpl
 * @Description TODO
 * @Date 2023/2/2 14:47
 * @Version 1.0
 */
@Service
@Slf4j
public class BMSUserPasswordChangeLogServiceImpl extends ServiceImpl<BMSUserPasswordChangeLogMapper, BMSUserPasswordChangeLog> implements BMSUserPasswordChangeLogService {

    @Resource
    private BMSUserPasswordChangeLogMapper bmsUserPasswordChangeLogMapper;

    @Override
    public Boolean updateUserPasswordChangeLog(Long userId) {
        BMSUserPasswordChangeLog bmsUserPasswordChangeLog = new BMSUserPasswordChangeLog();
        bmsUserPasswordChangeLog.setModifyPasswordTime(LocalDateTime.now());
        UpdateWrapper<BMSUserPasswordChangeLog> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_id", userId);
        int num = bmsUserPasswordChangeLogMapper.update(bmsUserPasswordChangeLog, updateWrapper);
        return num != 0;
    }

    @Override
    public void insertUserPasswordChangeLog(Long userId) {
        BMSUserPasswordChangeLog bmsUserPasswordChangeLog = new BMSUserPasswordChangeLog();
        bmsUserPasswordChangeLog.setUserId(userId);
        bmsUserPasswordChangeLog.setModifyPasswordTime(LocalDateTime.now());
        bmsUserPasswordChangeLogMapper.insert(bmsUserPasswordChangeLog);
    }

    @Override
    public BMSUserPasswordChangeLog selectOneByUserId(Long userId) {
        QueryWrapper<BMSUserPasswordChangeLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return bmsUserPasswordChangeLogMapper.selectOne(queryWrapper);
    }

}
